import Color from './Color';

export default class ColorScheme {
  constructor(value: {
    primary: Color,
    onPrimary: Color,
    background: Color,
    onBackground: Color,
    divider?: Color,
  }) {
    this.primary = value.primary,
    this.onPrimary = value.onPrimary,
    this.background = value.background;
    this.onBackground = value.onBackground;
    this.primary = value.primary;
    this.divider = value.divider ?? value.onBackground.withOpacity(0.15);
  }

  readonly primary: Color;
  readonly onPrimary: Color;
  readonly background: Color;
  readonly onBackground: Color;
  readonly divider: Color;

  copyWith(value: {
    primary?: Color,
    onPrimary?: Color,
    background?: Color,
    onBackground?: Color,
    divider?: Color,
  }): ColorScheme {
    return new ColorScheme({
      primary: value.primary ?? this.primary,
      onPrimary: value.onPrimary ?? this.onPrimary,
      background: value.background ?? this.background,
      onBackground: value.onBackground ?? this.onBackground,
      divider: value.divider ?? this.divider,
    });
  }

  copyFromJson(json?: any): ColorScheme {
    let obj = {};
    if (json) {
      Object.entries<Color>(json).forEach(([k, v]) => {
        obj[k] = new Color(v.value);
      });
    }
    return this.copyWith(obj);
  }
}